// 项目信息
function findSysinfo($scope, CertusFormAjax, CertusJsonAjax) {

    var deptIds = "";
    var compIds = "";
    this.getDepts = function () {
        var company = $("#company").val();
        if (company != "") {
            findCompDepts(company, deptIds);
        } else {
            findCompDepts(compIds, deptIds);
        }
    }

    this.findCompDepts = function (company, depts) {
        CertusFormAjax.ajax("findCompDepts", {
            "compCodes": company,
            "deptIds": depts,
            "isBm":"BM"
        }, function (response) {
            var data = response.data;
            $scope.dept = data;
        });
    };

    this.findAllDepts = function (dept) {
        CertusFormAjax.ajax("findQDepts", {
            "deptIds": dept
        }, function (response) {
            var data = response.data;
            $scope.dept = data;
        });
    }
    CertusFormAjax.ajax("isCrcd", {
        "code": "XMXX"
    }, function (response) {
        var data = JSON.parse(response.data);
        deptIds = data.deptCode;
        compIds = data.comanyCode;
        if (data.comanyCode != "") {
            CertusFormAjax.ajax("companyListByCode", {
                "code": data.comanyCode
            }, function (response) {
                $scope.comp = JSON.parse(response.data);
            });
            findCompDepts(data.comanyCode, deptIds);
        } else {
            $("#company").attr("disabled", "disabled");
            findAllDepts(data.deptCode);
        }

        if (data.isTrue == true) {
            searchs("", "1", deptIds, compIds, getBeforeDate(-2), getBeforeDate(2));
        } else {
            CertusFormAjax.ajax("getDeptCode", {}, function (response) {
                var data1 = response.data;
                $scope.deptCode = data1;
                $("#deptCode").attr("disabled", "disabled");
                $("#deptFlag").html("归属");
                //默认查询
                searchs(data1, "1", deptIds, compIds, getBeforeDate(-8), getBeforeDate(2));
            });
        }
    });

    this.searchs = function (proType, code, deptCode, company, startTime, endTime) {
        //未填写进展的项目列表
        var msgColumns4 = [{
            id: 'operation',
            title: '项目名称',
            type: 'string',
            // width: 150,
            columnClass: 'text-left',
            resolution: function (value, record) {
                var content = '';
                content += '<a href="javascript:findDetail(' + record.id + ');">' + record.pro_name + '</a>';
                return content;
            }
        }, {
            id: 'stage_code',
            title: '项目阶段',
            type: 'string',
            width: 100,
            columnClass: 'text-center',
            resolution: function (value) {
                var content = '';
                if (value == 1) {
                    content = '线索阶段';
                }
                if (value == 2||value == 3) {
                    content = '运作阶段';
                }
                if (value == 4) {
                    content = '合同阶段';
                }
                if (value == 5) {
                    content = '交付阶段';
                }
                if (value == 6) {
                    content = '回款阶段';
                }
                return content;
            }
        }, {
            id: 'department_name',
            title: '归属部门',
            type: 'string',
            width: 200,
            columnClass: 'text-center',
        }, {
            id: 'mgUser',
            title: '项目经理',
            type: 'string',
            width: 75,
            columnClass: 'text-center',
        }, {
            id: 'xsUser',
            title: '线索负责人',
            type: 'string',
            width: 100,
            columnClass: 'text-center',
        }, {
            id: 'cpUser',
            title: '产品经理',
            type: 'string',
            width: 75,
            columnClass: 'text-center',
        }, {
            id: 'jfUser',
            title: '交付经理',
            type: 'string',
            width: 75,
            columnClass: 'text-center',
        }, {
            id: 'sUser',
            title: '销售经理',
            type: 'string',
            width: 75,
            columnClass: 'text-center',
        }];
        $("#msgContainer4").empty();
        $("#msgToolBarContainer4").empty();
        CertusJsonAjax.dataInit("findYglProInfo", {
            "proType": proType,
            "code": code,
            "deptCode": deptCode,
            "compCode": company
        }, msgColumns4, 'msgContainer4', 'msgToolBarContainer4');
    }
    this.findDetail = function (proId) {
        $scope.proId = proId;
        probox($scope, CertusFormAjax);
    }

    $(".searchs").on('click', function () {
        var proType = $("#proType").val();
        var deptCode = $("#deptCode").val();
        var code = $("#code").val();
        if (code == "2" || code == "3") {
            if (deptCode == "") {
                layer.msg("请选择一个部门");
                return;
            }
        } else {
            if (deptCode == "") {
                deptCode = deptIds;
            }
        }
        var company = $("#company").val();
        if (company == "") {
            company = compIds;
        }
        searchs(proType, code, deptCode, company, "", "");
    });
    $("#datetime-star").val(getBeforeDate(-2));
    $("#datetime-2").val(getBeforeDate(2));
}
//n为你要传入的参数，当前为0，前一天为-1，后一天为1
function getBeforeDate(n) {
    var date = new Date();
    var year, month, day;
    date.setDate(date.getDate() + n);
    year = date.getFullYear();
    month = date.getMonth() + 1;
    day = date.getDate();
    s = year + '-' + (month < 10 ? ('0' + month) : month) + '-' + (day < 10 ? ('0' + day) : day);
    return s;
}

function findProxx($scope, CertusFormAjax) {
    var deptIds = "";
    var compIds = "";
    this.getDepts = function () {
        var company = $("#company").val();
        if (company != "") {
            findCompDepts(company, deptIds);
        } else {
            findCompDepts(compIds, deptIds);
        }
    }

    this.findCompDepts = function (company, depts) {
        CertusFormAjax.ajax("findCompDepts", {
            "compCodes": company,
            "deptIds": depts,
            "isBm":"BM"
        }, function (response) {
            var data = response.data;
            $scope.dept = data;
        });
    };

    this.findAllDepts = function (dept) {
        CertusFormAjax.ajax("findQDepts", {
            "deptIds": dept
        }, function (response) {
            var data = response.data;
            $scope.dept = data;
        });
    };
    CertusFormAjax.ajax("isCrcd", {
        "code": "XMXX"
    }, function (response) {
        var data = JSON.parse(response.data);
        deptIds = data.deptCode;
        compIds = data.comanyCode;
        if (data.comanyCode != "") {
            CertusFormAjax.ajax("companyListByCode", {
                "code": data.comanyCode
            }, function (response) {
                $scope.comp = JSON.parse(response.data);
            });
            findCompDepts(data.comanyCode, deptIds);
        } else {
            $("#company").attr("disabled", "disabled");
            findAllDepts(data.deptCode);
        }

        // if (data.isTrue == true) {
        //     search1("", deptIds,compIds);
        // } else {
        //     CertusFormAjax.ajax("getDeptCode", {}, function (response) {
        //         var data1 = response.data;
        //         $scope.deptCode = data1;
        //         $("#deptCode").attr("disabled", "disabled");
        //         $("#deptFlag").html("归属");
        //         //默认查询
        //         search1("", deptIds,compIds);
        //     });
        // }
    });
    this.search1 = function (proName, deptId, companyCode) {
        var msgColumns4 = [{
            id: 'operation',
            title: '项目名称',
            type: 'string',
            columnClass: 'text-left',
            resolution: function (value, record) {
                var content = '';
                content += '<a href="javascript:findDetails(' + record.id + ');">' + record.proName + '</a>';
                return content;
            }
        }, {
            id: 'stageCode',
            title: '项目阶段',
            type: 'string',
            width: 100,
            columnClass: 'text-center',
            resolution: function (value) {
                var content = '';
                if (value == 1) {
                    content += '线索阶段';
                }
                if (value == 2||value == 3) {
                    content += '运作阶段';
                }
                if (value == 4) {
                    content += '合同阶段';
                }
                if (value == 5) {
                    content += '交付阶段';
                }
                if (value == 6) {
                    content += '回款阶段';
                }
                return content;
            }
        }, {
            id: 'deptName',
            title: '归属部门',
            type: 'string',
            width: 200,
            columnClass: 'text-center',
        }, {
            id: 'proFzuser',
            title: '项目负责人',
            type: 'string',
            width: 100,
            columnClass: 'text-center',
        }, {
            id: 'xsUser',
            title: '线索负责人',
            type: 'string',
            width: 100,
            columnClass: 'text-center'
        }, {
            id: 'proType',
            title: '项目类型',
            type: 'string',
            width: 100,
            columnClass: 'text-center',
            resolution: function (value) {
                var content = '';
                if (value == "XS") {
                    content += '销售类';
                } else if (value == "ZL") {
                    content += '战略类';
                } else if (value == "YF") {
                    content += '研发类';
                } else if (value == "BM") {
                    content += '部门类';
                } else if (value == "SW") {
                    content += '事务类';
                } else {
                    content += '测试类';
                }
                return content;
            }
        }, {
            id: 'proState',
            title: '状态',
            type: 'string',
            width: 80,
            codeTable: status,
            hideType: 'sm|xs',
            columnClass: 'text-center',
            resolution: function (value) {
                var content = '';
                if (value == 1) {
                    content += '<span style="background:#5bc0de;padding:2px 10px;color:white;">运行中</span>';
                }
                if (value == 2) {
                    content += '<span style="background:#d9534f;padding:2px 10px;color:white;">已关闭</span>';
                }
                if (value == 3) {
                    content += '<span style="background:#5cb85c;padding:2px 10px;color:white;">已完结</span>';
                }
                if (value == 4) {
                    content += '<span style="background:#f8d347;padding:2px 10px;color:white;">已暂停</span>';
                }
                return content;
            }
        }];
        $("#xxContainer").empty();
        $("#xxToolBarContainer").empty();
        CertusFormAjax.ajax('getAllProList', {
            "proName": proName,
            "deptId": deptId,
            "companyCode": companyCode
        }, function (response) {
            var makingOption = {
                lang: 'zh-cn',
                ajaxLoad: false,
                extraWidth: 20,
                // loadURL:'url',
                exportFileName: '项目查询列表',
                datas: response.data,
                columns: msgColumns4,
                gridContainer: 'xxContainer',
                toolbarContainer: 'xxToolBarContainer',
                tools: '',
                pageSize: 10,
                pageSizeLimit: [10, 15, 20]
            };
            var makingGrid = $.fn.dlshouwen.grid.init(makingOption);
            makingGrid.load();
        })
    };
    $(".searchs").on('click', function () {
        var proName = $("#proName").val();
        var company = $("#company").val();
        var deptCode = $("#deptCode").val();
        search1(proName, deptCode, company);
    });
    search1("", "", "");
    this.findDetails = function (proId) {
        $scope.proId = proId;
        probox($scope, CertusFormAjax);
    }
}

function findZdgzxx($scope, CertusFormAjax) {
    var deptIds = "";
    var compIds = "";
    this.getDepts = function () {
        var company = $("#company").val();
        if (company != "") {
            findCompDepts(company, deptIds);
        } else {
            findCompDepts(compIds, deptIds);
        }
    }

    this.findCompDepts = function (company, depts) {
        CertusFormAjax.ajax("findCompDepts", {
            "compCodes": company,
            "deptIds": depts,
            "isBm":"BM"
        }, function (response) {
            var data = response.data;
            $scope.dept = data;
        });
    };

    this.findAllDepts = function (dept) {
        CertusFormAjax.ajax("findQDepts", {
            "deptIds": dept
        }, function (response) {
            var data = response.data;
            $scope.dept = data;
        });
    };
    CertusFormAjax.ajax("isCrcd", {
        "code": "ZDGZ"
    }, function (response) {
        var data = JSON.parse(response.data);
        deptIds = data.deptCode;
        compIds = data.comanyCode;
        if (data.comanyCode != "") {
            CertusFormAjax.ajax("companyListByCode", {
                "code": data.comanyCode
            }, function (response) {
                $scope.comp = JSON.parse(response.data);
            });
            findCompDepts(data.comanyCode, deptIds);
        } else {
            $("#company").attr("disabled", "disabled");
            findAllDepts(data.deptCode);
        }
    });

    var msgColumns4 = [{
        id: 'proName',
        title: '项目名称',
        type: 'string',
        width: 200,
        columnClass: 'text-center',
        resolution: function (value, record) {
            var content = '';
            content += '<a href="javascript:findDetails(' + record.id + ');">' + record.proName + '</a>';
            return content;
        }
    }, {
        id: 'krsDesc',
        title: '重点任务',
        type: 'string',
        width: 200,
        columnClass: 'text-left',
    }, {
        id: 'rwDesc',
        title: '当前进展',
        type: 'string',
        width: 200,
        columnClass: 'text-left',
    }, {
        id: 'nextPlan',
        title: '下一步计划',
        type: 'string',
        columnClass: 'text-left',
    }, {
        id: 'updateTime',
        title: '更新时间',
        type: 'date',
        width: 100,
        format: 'yyyy-MM-dd',
        otype: 'time_stamp_ms',
        columnClass: 'text-center'
    }, {
        id: 'userName',
        title: '负责人',
        type: 'string',
        width: 75,
        columnClass: 'text-center'
    }];

    // 项目目标
    var prointColumns = [{
        id: 'proName',
        title: '项目名称',
        type: 'string',
        width: 200,
        columnClass: 'text-center',
        resolution: function (value, record) {
            var content = '';
            content += '<a href="javascript:findDetails(' + record.id + ');">' + record.proName + '</a>';
            return content;
        }
    }, {
        id: 'proTarget',
        title: '项目目标',
        type: 'string',
        columnClass: 'text-left',
    }, {
        id: 'userName',
        title: '目标负责人',
        type: 'string',
        width: 100,
        columnClass: 'text-center',
    }, {
        id: 'finishTime',
        title: '完成时间',
        type: 'date',
        format: 'yyyy-MM-dd',
        otype: 'time_stamp_ms',
        width: 100,
        columnClass: 'text-center'
    }];

    // 项目指标
    var zbColumns = [{
        id: 'proName',
        title: '项目名称',
        type: 'string',
        width:200,
        columnClass: 'text-center',
        resolution: function (value, record) {
            var content = '';
            content += '<a href="javascript:findDetails(' + record.id + ');">' + record.proName + '</a>';
            return content;
        }
    }, {
        id: 'wntyName',
        title: '指标名称',
        width: 200,
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'wntyDesc',
        title: '指标描述',
        type: 'string',
        columnClass: 'text-left'
    }, {
        id: 'finishTime',
        title: '完成时间',
        type: 'string',
        width: 100,
        columnClass: 'text-center'
    }];
    this.search = function (proName, deptCode, compCode) {
        $("#zdContainer").empty();
        $("#zdToolBarContainer").empty();
        CertusFormAjax.ajax('findImWorks', {
            "proName": proName,
            "deptCode": deptCode,
            "compCode": compCode
        }, function (response) {
            var makingOption = {
                lang: 'zh-cn',
                ajaxLoad: false,
                extraWidth: 20,
                // loadURL:'url',
                exportFileName: '项目查询列表',
                datas: response.data,
                columns: msgColumns4,
                gridContainer: 'zdContainer',
                toolbarContainer: 'zdToolBarContainer',
                tools: '',
                pageSize: 10,
                pageSizeLimit: [10, 15, 20]
            };
            var makingGrid = $.fn.dlshouwen.grid.init(makingOption);
            makingGrid.load();
        });

        $("#mbContainer").empty();
        $("#mbToolBarContainer").empty();
        CertusFormAjax.ajax("findImTargets", {
            "proName": proName,
            "deptCode": deptCode,
            "compCode": compCode
        }, function (response) {
            var proinOption = {
                lang: 'zh-cn',
                ajaxLoad: false,
                extraWidth: 20,
                // loadURL:'url',
                exportFileName: '项目指标',
                datas: response.data,
                columns: prointColumns,
                gridContainer: 'mbContainer',
                toolbarContainer: 'mbToolBarContainer',
                tools: '',
                pageSize: 10,
                pageSizeLimit: [10, 15, 20]
            };
            var proinGrid = $.fn.dlshouwen.grid.init(proinOption);
            proinGrid.load();
        });

        $("#zbContainer").empty();
        $("#zbToolBarContainer").empty();
        CertusFormAjax.ajax("findImWarranty", {
            "proName": proName,
            "deptCode": deptCode,
            "compCode": compCode
        }, function (response) {
            var proinOption = {
                lang: 'zh-cn',
                ajaxLoad: false,
                extraWidth: 20,
                // loadURL:'url',
                exportFileName: '项目指标',
                datas: response.data,
                columns: zbColumns,
                gridContainer: 'zbContainer',
                toolbarContainer: 'zbToolBarContainer',
                tools: '',
                pageSize: 10,
                pageSizeLimit: [10, 15, 20]
            };
            var proinGrid = $.fn.dlshouwen.grid.init(proinOption);
            proinGrid.load();
        });
    };
    search("", "", "");
    $(".searchs").on('click', function () {
        var proName = $("#proName").val();
        var company = $("#company").val();
        var deptCode = $("#deptCode").val();
        search(proName, deptCode, company);
    });

    this.findDetails = function (proId) {
        $scope.proId = proId;
        probox($scope, CertusFormAjax);
    }
}